//
//  HomeViewController.swift
//  xiaofenshu
//
//  Created by zhu jinlong on 2021/5/18.
//

import UIKit
import XLPagerTabStrip
class HomeViewController: ButtonBarPagerTabStripViewController {

    override func viewDidLoad() {
        settings.style.selectedBarHeight = 3
        settings.style.selectedBarBackgroundColor = UIColor.init(named: "mainColor")!
        
        settings.style.buttonBarItemBackgroundColor = .clear
        settings.style.buttonBarItemTitleColor = .label
        settings.style.buttonBarItemFont = .systemFont(ofSize: 16.0)
       
        super.viewDidLoad()
        
        containerView.bounces = false
        changeCurrentIndexProgressive = { (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in

            guard changeCurrentIndex == true else {return}

            oldCell?.label.textColor = .secondaryLabel
            newCell?.label.textColor = .label
            
            if animated {
                UIView.animate(withDuration: 0.1, animations: { () -> Void in
                    newCell?.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
                    oldCell?.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
                    })
                }else {
                    newCell?.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
                    oldCell?.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
                }
        }
        
        DispatchQueue.main.async {
            self.moveToViewController(at: 1, animated: false)
        }
        
    }
    
    override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
        let followVc = storyboard!.instantiateViewController(identifier: followVcId)
        let disVc = storyboard!.instantiateViewController(identifier: disovryVcId)
        let nearVc = storyboard!.instantiateViewController(identifier: nearById)
        
        return [followVc,disVc,nearVc]
    }
    

}
